package cn.xdf.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping("/demo07")
public class Demo07Controller_RequestAttribute {

    @GetMapping("/demo01")
    public String demo01(Model model)throws IOException{

        //在请求域添加几个参数
        model.addAttribute("username","zhangsan");
        model.addAttribute("password","123");

        return "/demo07/demo02";
    }

    @GetMapping("/demo02")
    public void demo02(
            @RequestAttribute("username") String name,// 获取请求域中的username属性值
            @RequestAttribute String password,// 获取请求域中的password属性值
            HttpServletResponse response
    )throws IOException{
        response.getWriter().println("username:"+name);
        response.getWriter().println("password:"+password);
    }
}
